]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
tests: Port findUrl() test to jasmine
authorFlorian Müllner <fmuellner@gnome.org>
Sat, 20 Jan 2024 08:37:54 +0000 (09:37 +0100)
committerMarge Bot <marge-bot@gnome.org>
Tue, 21 May 2024 13:42:28 +0000 (13:42 +0000)
Based on https://bugzilla.gnome.org/show_bug.cgi?id=783738
from Sam Spilsbury.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>

tests/meson.build
tests/unit/url.js

index 851a9c17cf1e2a5c7f5f0ff666d172e9fada69ed..4a6025b9b852b9fdd75386d44acdcbb268d0028f 100644 (file)
@@ -27,6 +27,7 @@ unit_tests = [
     'markup',
     'params',
     'signalTracker',
+    'url',
 ]
 
 foreach test : unit_tests
@@ -45,7 +46,6 @@ foreach test : unit_tests
 endforeach
 
 legacy_tests = [
-    'url',
     'versionCompare',
 ]
 
index 00ad66dcbe6d341156ca85889c3a7b8389c45460..6b3d93c82e1915f5c5f5f0a82821b272d170d6ab 100644 (file)
 
 // Test cases for MessageTray URLification
 
-const JsUnit = imports.jsUnit;
-
 import 'resource:///org/gnome/shell/ui/environment.js';
+import {findUrls} from 'resource:///org/gnome/shell/misc/util.js';
 
-import * as Util from 'resource:///org/gnome/shell/misc/util.js';
-
-const tests = [
-    {
-        input: 'This is a test',
-        output: [],
-    },
-    {
-        input: 'This is http://www.gnome.org a test',
-        output: [{url: 'http://www.gnome.org', pos: 8}],
-    },
-    {
-        input: 'This is http://www.gnome.org',
-        output: [{url: 'http://www.gnome.org', pos: 8}],
-    },
-    {
-        input: 'http://www.gnome.org a test',
-        output: [{url: 'http://www.gnome.org', pos: 0}],
-    },
-    {
-        input: 'http://www.gnome.org',
-        output: [{url: 'http://www.gnome.org', pos: 0}],
-    },
-    {
-        input: 'Go to http://www.gnome.org.',
-        output: [{url: 'http://www.gnome.org', pos: 6}],
-    },
-    {
-        input: 'Go to http://www.gnome.org/.',
-        output: [{url: 'http://www.gnome.org/', pos: 6}],
-    },
-    {
-        input: '(Go to http://www.gnome.org!)',
-        output: [{url: 'http://www.gnome.org', pos: 7}],
-    },
-    {
-        input: 'Use GNOME (http://www.gnome.org).',
-        output: [{url: 'http://www.gnome.org', pos: 11}],
-    },
-    {
-        input: 'This is a http://www.gnome.org/path test.',
-        output: [{url: 'http://www.gnome.org/path', pos: 10}],
-    },
-    {
-        input: 'This is a www.gnome.org scheme-less test.',
-        output: [{url: 'www.gnome.org', pos: 10}],
-    },
-    {
-        input: 'This is a www.gnome.org/scheme-less test.',
-        output: [{url: 'www.gnome.org/scheme-less', pos: 10}],
-    },
-    {
-        input: 'This is a http://www.gnome.org:99/port test.',
-        output: [{url: 'http://www.gnome.org:99/port', pos: 10}],
-    },
-    {
-        input: 'This is an ftp://www.gnome.org/ test.',
-        output: [{url: 'ftp://www.gnome.org/', pos: 11}],
-    },
-    {
-        input: 'https://www.gnome.org/(some_url,_with_very_unusual_characters)',
-        output: [{url: 'https://www.gnome.org/(some_url,_with_very_unusual_characters)', pos: 0}],
-    },
-    {
-        input: 'https://www.gnome.org/(some_url_with_unbalanced_parenthesis',
-        output: [{url: 'https://www.gnome.org/', pos: 0}],
-    },
-    {
-        input: 'https://www.gnome.org/‎ plus trailing junk',
-        output: [{url: 'https://www.gnome.org/', pos: 0}],
-    },
+describe('findUrls()', () => {
+    const urlParameters = [
+        {
+            input: 'This is a test',
+            output: [],
+        },
+        {
+            input: 'This is http://www.gnome.org a test',
+            output: [{url: 'http://www.gnome.org', pos: 8}],
+        },
+        {
+            input: 'This is http://www.gnome.org',
+            output: [{url: 'http://www.gnome.org', pos: 8}],
+        },
+        {
+            input: 'http://www.gnome.org a test',
+            output: [{url: 'http://www.gnome.org', pos: 0}],
+        },
+        {
+            input: 'http://www.gnome.org',
+            output: [{url: 'http://www.gnome.org', pos: 0}],
+        },
+        {
+            input: 'Go to http://www.gnome.org.',
+            output: [{url: 'http://www.gnome.org', pos: 6}],
+        },
+        {
+            input: 'Go to http://www.gnome.org/.',
+            output: [{url: 'http://www.gnome.org/', pos: 6}],
+        },
+        {
+            input: '(Go to http://www.gnome.org!)',
+            output: [{url: 'http://www.gnome.org', pos: 7}],
+        },
+        {
+            input: 'Use GNOME (http://www.gnome.org).',
+            output: [{url: 'http://www.gnome.org', pos: 11}],
+        },
+        {
+            input: 'This is a http://www.gnome.org/path test.',
+            output: [{url: 'http://www.gnome.org/path', pos: 10}],
+        },
+        {
+            input: 'This is a www.gnome.org scheme-less test.',
+            output: [{url: 'www.gnome.org', pos: 10}],
+        },
+        {
+            input: 'This is a www.gnome.org/scheme-less test.',
+            output: [{url: 'www.gnome.org/scheme-less', pos: 10}],
+        },
+        {
+            input: 'This is a http://www.gnome.org:99/port test.',
+            output: [{url: 'http://www.gnome.org:99/port', pos: 10}],
+        },
+        {
+            input: 'This is an ftp://www.gnome.org/ test.',
+            output: [{url: 'ftp://www.gnome.org/', pos: 11}],
+        },
+        {
+            input: 'https://www.gnome.org/(some_url,_with_very_unusual_characters)',
+            output: [{url: 'https://www.gnome.org/(some_url,_with_very_unusual_characters)', pos: 0}],
+        },
+        {
+            input: 'https://www.gnome.org/(some_url_with_unbalanced_parenthesis',
+            output: [{url: 'https://www.gnome.org/', pos: 0}],
+        },
+        {
+            input: 'https://www.gnome.org/‎ plus trailing junk',
+            output: [{url: 'https://www.gnome.org/', pos: 0}],
+        },
 
-    {
-        input: 'Visit http://www.gnome.org/ and http://developer.gnome.org',
-        output: [{url: 'http://www.gnome.org/', pos: 6},
-            {url: 'http://developer.gnome.org', pos: 32}],
-    },
+        {
+            input: 'Visit http://www.gnome.org/ and http://developer.gnome.org',
+            output: [{url: 'http://www.gnome.org/', pos: 6},
+                {url: 'http://developer.gnome.org', pos: 32}],
+        },
 
-    {
-        input: 'This is not.a.domain test.',
-        output: [],
-    },
-    {
-        input: 'This is not:a.url test.',
-        output: [],
-    },
-    {
-        input: 'This is not:/a.url/ test.',
-        output: [],
-    },
-    {
-        input: 'This is not:/a.url/ test.',
-        output: [],
-    },
-    {
-        input: 'This is not@a.url/ test.',
-        output: [],
-    },
-    {
-        input: 'This is surely@not.a/url test.',
-        output: [],
-    },
-];
+        {
+            input: 'This is not.a.domain test.',
+            output: [],
+        },
+        {
+            input: 'This is not:a.url test.',
+            output: [],
+        },
+        {
+            input: 'This is not:/a.url/ test.',
+            output: [],
+        },
+        {
+            input: 'This is not:/a.url/ test.',
+            output: [],
+        },
+        {
+            input: 'This is not@a.url/ test.',
+            output: [],
+        },
+        {
+            input: 'This is surely@not.a/url test.',
+            output: [],
+        },
+    ];
 
-for (let i = 0; i < tests.length; i++) {
-    let match = Util.findUrls(tests[i].input);
+    for (const param of urlParameters) {
+        const {input, output} = param;
+        const findsOrDoesNotFind = output.length > 0
+            ? 'finds'
+            : 'does not find';
 
-    JsUnit.assertEquals(`Test ${i} match length`,
-        match.length, tests[i].output.length);
-    for (let j = 0; j < match.length; j++) {
-        JsUnit.assertEquals(`Test ${i}, match ${j} url`, match[j].url, tests[i].output[j].url);
-        JsUnit.assertEquals(`Test ${i}, match ${j} position`, match[j].pos, tests[i].output[j].pos);
+        it(`${findsOrDoesNotFind} URLs in "${input}"`, () => {
+            expect(findUrls(input)).toEqual(output);
+        });
     }
-}
+});